﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Configuration;
using Db8.DataAccess;
using System.Web.Security;

namespace Db8
{

    static class MobileHelper
    {
        public static bool IsSupportedMobileDevice(this HttpRequestBase request)
        {
            if (ClientSettings.ViewMode != "")
            {
                string mode = ClientSettings.ViewMode;
                if (mode == "mobile")
                    return true;
                else if (mode == "full")
                    return false;
            }

            bool isMobile = request.Browser.IsMobileDevice;
            string userAgent = request.UserAgent.ToLowerInvariant();

            isMobile = isMobile || (userAgent.Contains("iphone")
                                || userAgent.Contains("blackberry")
                                || userAgent.Contains("mobile")
                                || userAgent.Contains("windows ce")
                                || userAgent.Contains("opera mini")
                                || userAgent.Contains("palm")
                                || userAgent.Contains("fennec")
                                || userAgent.Contains("adobeair")
                                || userAgent.Contains("ripple")
                );

            return isMobile;
        }
    }
}